# peewee测试
from datetime import datetime
from .base import BaseHandler
from models.user import *
import json

from datetime import datetime
from .base import BaseHandler
from models.user import *
import json
class TeacherHandler(BaseHandler):
    #添加
    async def post(self):
        # data = json.loads(self.request.body)
        teacher = {"name":'zss','age':18,'subject':'2342'}
        await self.application.objects.create(Teacher,**teacher)
        self.write({"code":200})
    #修改
    async def put(self):
        t = Teacher(id=1,name='234')
        await self.application.objects.update(t)
        self.write({"code":200})

    #删除
    async def delete(self):
        t = Teacher(id=1)
        await self.application.objects.delete(t)
        self.write({"code":200})
    #查询
    async def get(self):
        #查询单表
        teacher = await self.application.objects.get(Teacher,id=2)
        create_time = datetime.strftime(teacher.create_time,"%Y-%m-%d %H:%M:%S")
        t ={'id':teacher.id,'name':teacher.name,'addtime':create_time}
        self.write({"code":200,'tea':t})